package com.hxkj.controller.userCenter;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.SysUser;
import com.hxkj.service.userCenter.UserManagementService;
import com.platform.common.domain.to.PageTo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

@RestController
@RequestMapping(value = "/userManagement")
public class UserManagementController {

    @Autowired
    private UserManagementService userManagementService;

    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public Callable<PageInfo<SysUser>> getList(@ModelAttribute SysUser user, @ModelAttribute PageTo pageParam) throws Exception{
        return () -> userManagementService.getList(user, pageParam);
    }

    @RequestMapping(value = "/getUser", method = RequestMethod.POST)
    public Callable<SysUser> getUser(@ModelAttribute SysUser user) throws Exception{
        return () -> userManagementService.getUser(user);
    }

    /**
     * 启用/禁用用户，添加权限控制
     * @param user
     * @throws Exception
     */
    @RequiresPermissions("sysUser:operation")
    @RequestMapping(value = "/modifyUserStatus", method = RequestMethod.POST)
    public void modifyUserStatus(@ModelAttribute SysUser user) throws Exception{
        userManagementService.modifyUserStatus(user);
    }

    /**
     * 编辑用户，添加权限控制
     * @param user
     * @throws Exception
     */
    @RequiresPermissions("sysUser:edit")
    @RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
    public void modifyUser(@ModelAttribute SysUser user) throws Exception{
        userManagementService.modifyUser(user);
    }

}
